gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\generalp\mahalan.m
function dist = mahalan(X,mi,sigma) % MAHALAN Mahalanobis distance. % dist=mahalan(X,mi,sigma) % % MAHALAN calculates Mahalanobis distance for given vectors % in the matrix X, where mi is the vector from which the distance % is calculated and sigma is the covariance matrix (bending of % the feature space). % % Input: % X [NxK] matrix of K vectors for which the distance is computed, % where N is the dimension of the feature space. % mi [Nx1] mean vlaue. % sigma [NxN] covariance matrix. % % Output: % dist [1xK] vector of distances for given vectors in the matrix X. % % Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac % (c) Czech Technical University Prague, http://cmp.felk.cvut.cz % Written Vojtech Franc (diploma thesis) 19.3.2000 % Modifications % 27-Oct-2001, V.Franc % 25. 6.00 V. Hlavac, comments into English. % gets # of points K=size(X,2); % gets dim DIM=size(X,1); % makes mi a column vector mi=mi(:); % computes it for all the points in matrix X if DIM == 1, dist=((X-repmat(mi,1,K))'*inv(sigma).*(X-repmat(mi,1,K))')'; else dist=sum( ((X-repmat(mi,1,K))'*inv(sigma).*(X-repmat(mi,1,K))')'); end